/**
 * FileName: AirETicketsService
 * Author:   Leopold
 * Date:     2018/9/11 19:56
 * Description:
 * History:
 */
package cn.mcsys.myadmin.modules.viewer.service.impl;

import cn.mcsys.myadmin.modules.viewer.dao.AirETicketsDao;
import cn.mcsys.myadmin.modules.viewer.dao.AirTicketsDao;
import cn.mcsys.myadmin.modules.viewer.entity.AirETickets;
import cn.mcsys.myadmin.modules.viewer.entity.AirRideQrCode;
import cn.mcsys.myadmin.modules.viewer.entity.AirTickets;
import cn.mcsys.myadmin.modules.viewer.entity.AirViewerUser;
import cn.mcsys.myadmin.modules.viewer.service.AirETicketsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AirETicketsServiceImpl implements AirETicketsService {

    @Autowired
    private AirETicketsDao airETicketsDao;

    @Autowired
    private AirTicketsDao airTicketsDao;

    @Override
    public List<AirETickets> selectByUserId(Long id) {
        return airETicketsDao.selectByUserId(id);
    }

    @Override
    public List<AirTickets> selectByTypeAndNumber(int type, String number) {
        return airTicketsDao.selectByTypeAndNumber(type,number);
    }

    @Override
    public void saveETicket(List<AirTickets> airTickets, AirViewerUser user) {
        for (AirTickets airTicket : airTickets) {
            AirETickets airETickets = new AirETickets();
            airETickets.setTicketDate(airTicket.getTicketDate());
            airETickets.setTicketNumber(airTicket.getTicketNumber());
            //票种
            airETickets.setTicketType(airTicket.getTicketType());
            airETickets.setUser(user);
            AirETickets ticket = airETicketsDao.selectBySelfETickets(airETickets);
            if(ticket == null){
                airETicketsDao.insert(airETickets);
            }
        }
    }

    @Override
    public List<AirETickets> selectByManyId(Long[] eTicketsId) {
        return airETicketsDao.selectByManyId(eTicketsId);
    }

    @Override
    public void setQrCodeId(Long[] airETickets, AirRideQrCode airRideQrCode) {
        airETicketsDao.updateQrCodeId(airETickets,airRideQrCode.getId());
    }


    @Override
    public List<AirETickets> selectMyAllETickets(Long id) {
        return airETicketsDao.selectMyAllETickets(id);
    }

    @Override
    public List<Long> selectByQrcodeId(Long qrcodeId) {
        return airETicketsDao.selectByQrcodeId(qrcodeId);
    }

    @Override
    public void batchUpdateQrcodeId(List<Long> airETicketIds) {
        airETicketsDao.batchUpdate(airETicketIds);
    }
}
